﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Xml;

namespace DDotNet.Web.UI.AutomatedPageBuilder.Configuration
{
    public sealed class AutomatedPageBuilderSettingsHandler : IConfigurationSectionHandler
    {
        ///<summary>
        ///Creates a configuration section handler.
        ///</summary>
        /// 
        ///<returns>
        ///The created section handler object.
        ///</returns>
        ///
        ///<param name="configContext">Configuration context object.</param>
        ///<param name="section">Section XML node.</param>
        ///<param name="parent">Parent object.</param><filterpriority>2</filterpriority>
        public object Create(object parent, object configContext, XmlNode section)
        {
            return (new AutomatedPageBuilderSettings(section));
        }

        /// <summary>
        /// Retorna as Configurações de DataBaseFactory
        /// </summary>
        /// <returns></returns>
        internal static AutomatedPageBuilderSettings GetSetting()
        {
            try
            {
                return (AutomatedPageBuilderSettings)ConfigurationManager.GetSection("D.NET/AutomatedPageBuilder/Settings");
            }
            catch (ConfigurationErrorsException e)
            {
                throw (new ConfigurationErrorsException("Não foi possível carregar as configurações para a DatabaseFactory. Verifique seu arquivo de configuração para verificar possíveis erros.", e));
            }
        }
    }
}
